package com.ww.springboot.boot.algorithm.leetcode1;

import java.util.TreeMap;

/**
 * 描述：treemap
 *
 * @author 🧑 ‍wanwei
 * @since 2022-04-21 09:03
 */
public class BS729我的日程安排表 {

    private static final TreeMap<Integer, Integer> calendar = new TreeMap();


    public static void main(String[] args) {

        System.out.println(book(10, 20));
        System.out.println(book(15, 25));
        System.out.println(book(20, 30));
    }

    public static boolean book(int start, int end) {
        Integer prev = calendar.floorKey(start),
                next = calendar.ceilingKey(start);
        if ((prev == null || calendar.get(prev) <= start) &&
                (next == null || end <= next)) {
            calendar.put(start, end);
            return true;
        }
        return false;
    }
}
